package com.example;

import com.example.entity.User;
import com.example.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @PostMapping(value="/login")
    public ModelAndView login(HttpServletRequest request, ModelAndView mv, User u)
    {
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        u=userService.Login(username, password);
        if(u!=null) {
            mv.setViewName("User");
            mv.addObject("info", username);
            return mv;
        }
        mv.setViewName("login");
        return mv;

    }

}

